package com.xingdata.jjxc.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xingdata.jjxc.R;

public class DeviceAdapter extends BaseAdapter {
	private ArrayList<BluetoothDevice> bluetoothDevices;
	private Context mContext;
	public DeviceAdapter(ArrayList<BluetoothDevice> bluetoothDevices, Activity activity) {
		this.mContext=activity;
		this.bluetoothDevices=bluetoothDevices;
	}

	@Override
	public int getCount() {
		return bluetoothDevices.size();
	}

	@Override
	public Object getItem(int position) {
		return bluetoothDevices.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.bluetooth_item, null);
			holder.DeviceName = (TextView) convertView.findViewById(R.id.DeviceName);
			holder.DeviceAddress = (TextView) convertView.findViewById(R.id.DeviceAddress);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.DeviceName.setText(bluetoothDevices.get(position).getName());
		holder.DeviceAddress.setText(bluetoothDevices.get(position).getAddress());
		return convertView;
	}
	
	private class ViewHolder {
		TextView DeviceName;
		TextView DeviceAddress;
	}

}
